package com.lxh.lxhcrm.controller.aftersale;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lxh.lxhcrm.model.pojos.CareRecord;
import com.lxh.lxhcrm.model.pojos.CareType;
import com.lxh.lxhcrm.model.pojos.Emp;
import com.lxh.lxhcrm.model.service.AfterSaleService;
import com.lxh.lxhcrm.model.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 开发团队 ：lxh
 * 开发人员 ：李兴洋
 * 开发时间 ：2020年2月27日23:11:22
 * 类的名称 ：CustomerCareController
 * 类的描述 ：售后模块中的客户关怀
 */
@RestController
@RequestMapping("/after-sale/customer-care")
public class CustomerCareController {
    @Autowired
    AfterSaleService afterSaleService;
    @Autowired
    EmpService empService;

//    所有关怀记录
    @RequestMapping("/care-list")
    public Map<String,Object> careList(Integer page , Integer size , String search , String kcName){
        Page<Object> obj = PageHelper.startPage(page, size);
        List<CareRecord> careRecordList = afterSaleService.findAllCustomerCare(search, kcName);

        Map<String,Object> kMap = new HashMap<>();
        kMap.put("total",obj.getTotal());
        kMap.put("rows",careRecordList);
        return kMap;
    }
//  添加关怀记录
    @RequestMapping("/add-care")
    @ResponseBody
    public void addCare(@RequestBody CareRecord careRecord){
        afterSaleService.addCareRecord(careRecord);
    }

//    关怀记录删除
    @RequestMapping("/delete-care")
    @ResponseBody
    public void deleteCare(Integer crNo){
        //System.out.println(crNo);
        afterSaleService.deleteCareRecord(crNo);
    }

//    员工表
    @RequestMapping("/emp-list")
    @ResponseBody
    public List<Emp> findAllEmp(){
        List<Emp> allEmp=empService.findEmpById(3);
        return allEmp;
    }

    //审核
    @RequestMapping("/cusCareCheck")
    @ResponseBody
    public void cusCareCheck(Integer careId){
        afterSaleService.careCheck(careId);
    }

    /** 所有关怀状态**/
    @RequestMapping("/careTypeList")
    public List<CareType> allCareType(){
        return afterSaleService.allCareType();
    }

    /** 添加关怀状态**/
    @RequestMapping("/add-careType")
    @ResponseBody
    public void addCareType (CareType ct){
        afterSaleService.addCareType(ct);
    }

    /** 删除关怀状态**/
    @RequestMapping("/delete-careType")
    @ResponseBody
    public void deleteCareType(Integer ctId){
        afterSaleService.deleteCareTypeById(ctId);
    }

}
